import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class RobotSim {
    public static void main(String[] args) {
        RobotSim solution21=new RobotSim();

    }
    public int robotSim(int[] commands, int[][] obstacles) {
        //首先定位一下四个方向
        int[][] dir = {{0,1},{1,0},{0,-1},{-1,0}};
        //初始方向为北方向
        int dirIndex = 0;
        Set<String> set =new HashSet<>();
        int x =0,y=0;
        int max =0;
        for(int i =0;i<obstacles.length;i++){
            String temp = obstacles[i][0]+","+obstacles[i][1];
            set.add(temp);
        }
        for(int i =0;i<commands.length;i++){
            if(commands[i]==-2){
                dirIndex = (dirIndex + 3) % 4;
            }else if(commands[i]==-1){
                dirIndex = (dirIndex+1) %4;
            }else{
                for(int j =1;j<=commands[i];j++){
                    int next_x= x +dir[dirIndex][0];
                    int next_y = y+dir[dirIndex][1];
                    if(set.contains(next_x+","+next_y)){
                        break;
                    }else{
                        x=next_x;
                        y=next_y;
                        max = Math.max(max,x*x+y*y);
                    }
                }
            }

        }
        return max;
    }
}
